package com.ruoyi.channel.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.channel.domain.ChannelMsgSent;
import com.ruoyi.channel.domain.TChannelDataConf;
import com.ruoyi.channel.domain.TChannelDataStaff;
import com.ruoyi.channel.domain.TChannelPushDis;
import com.ruoyi.channel.domain.vo.TChannelDataConfVo;
import com.ruoyi.channel.mapper.TChannelDataConfMapper;
import com.ruoyi.channel.mapper.TChannelDataStaffMapper;
import com.ruoyi.channel.mapper.TChannelPushDisMapper;
import com.ruoyi.channel.service.ChannelDisService;
import com.ruoyi.channel.service.ITChannelDataConfService;
import com.ruoyi.channelApi.domain.CfCrmRequest;
import com.ruoyi.channelApi.domain.ChannelRequest;
import com.ruoyi.channelApi.domain.common.ChannelCommonRequest;
import com.ruoyi.channelApi.domain.vo.TChannelPushVo;
import com.ruoyi.channelApi.mapper.TChannelPushMapper;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.JsonUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.customer.SentMessage;
import com.ruoyi.customer.domain.Customer;
import com.ruoyi.customer.domain.CustomerChange;
import com.ruoyi.customer.domain.Remark;
import com.ruoyi.customer.domain.TotalComster;
import com.ruoyi.customer.domain.vo.CustomerVo;
import com.ruoyi.customer.mapper.CustomerMapper;
import com.ruoyi.customer.mapper.RemarkMapper;
import com.ruoyi.customer.mapper.TotalComsterMapper;
import com.ruoyi.customer.service.CommonService;
import com.ruoyi.customer.service.DisCommonService;
import com.ruoyi.disCustomer.domain.TCustomerDisRecord;
import com.ruoyi.disCustomer.mapper.TCustomerDisRecordMapper;
import com.ruoyi.enums.BusTypeEnum;
import com.ruoyi.enums.ChannelPushEnum;
import com.ruoyi.enums.CompanyStatusEnum;
import com.ruoyi.enums.CustomerStatusEnum;
import com.ruoyi.system.mapper.SysUserMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.CollectionUtils;


@Service
@RequiredArgsConstructor
public class ChannelDisServiceImpl implements ChannelDisService {

    private final TChannelPushMapper channelPushMapper;
    private final TChannelPushDisMapper channelPushDisMapper;
    private final TotalComsterMapper totalComsterMapper;
    private final CustomerMapper customerMapper;
    private final RemarkMapper remarkMapper;
    private final SysUserMapper userMapper;
    private final TChannelDataConfMapper channelDataConfMapper;
    private final TChannelDataStaffMapper channelDataStaffMapper;
    private final DisCommonService disCommonService;
    private final ITChannelDataConfService channelDataConfService;
    private final TCustomerDisRecordMapper disRecordMapper;
    private final CommonService commonService;

    @Override
//    @Transactional(propagation = Propagation.NESTED)
    public Map<String, String> backChannelCustomerInfo(Long channelPushId) {
        try {
            // 获取渠道推送的客户信息
            TChannelPushVo tChannelPushVo = channelPushMapper.selectVoById(channelPushId);
            if (tChannelPushVo == null) {
                throw new ServiceException("推送数据没有获取到");
            }
            if (!StringUtils.isNotBlank(tChannelPushVo.getDataInfo())) {
                throw new ServiceException("配置信息有问题");
            }
            // 渠道来源
            String channelSource = tChannelPushVo.getChannelSource();
            String tel = tChannelPushVo.getTel();
            // 根据渠道类型查询要分配的人 --- 配置好信息
            LambdaQueryWrapper<TChannelDataConf> confWrapper = new LambdaQueryWrapper<>();
            confWrapper.eq(TChannelDataConf::getChannelSource, channelSource);
            TChannelDataConfVo tChannelDataConfVo = channelDataConfMapper.selectVoOne(confWrapper);
            if (tChannelDataConfVo == null) {
                throw new ServiceException("配置信息有问题");
            }
            // 处理渠道分配人员问题---获取最新的人进行分配
            TChannelPushDis tChannelPushDis = new TChannelPushDis();
            Map<String, String> mapMsg = new HashMap<>();
            mapMsg.put("flag", "0");
            mapMsg.put("msg", "正常完成");
            tChannelPushDis.setDataInfo(JsonUtils.toJsonString(mapMsg));
            Long disUserId = tChannelDataConfVo.getDisUserId();
            // 如果为空
            boolean disFlag = true;
            if (disUserId == -1) {
                // 更新人员信息
                this.channelDisUserId(tChannelDataConfVo.getId());
                // 根据渠道类型查询要分配的人 --- 配置好信息
                LambdaQueryWrapper<TChannelDataConf> dataConfWrapper = new LambdaQueryWrapper<>();
                dataConfWrapper.eq(TChannelDataConf::getChannelSource, channelSource);
                TChannelDataConfVo dataConfVo = channelDataConfMapper.selectVoOne(dataConfWrapper);
                if (dataConfVo == null) {
                    throw new ServiceException("配置信息有问题");
                }
                // 重新获取userId
                Long reUserId = dataConfVo.getDisUserId();
                if (reUserId == -1) {
                    disFlag = false;
                    mapMsg.put("flag", "4");
                    mapMsg.put("msg", "分配人员为空");
                    tChannelPushDis.setDataInfo(JsonUtils.toJsonString(mapMsg));
                    // 通知管理员去添加
                    this.sentToAdminDis(14L, tChannelDataConfVo.getChannelName(), "");
                    throw new ServiceException("最终没有可分配的人员");
                } else {
                    disUserId = reUserId;
                    tChannelDataConfVo.setDisUserId(disUserId);
                }
            }
            tChannelPushDis.setUserId(disUserId);
            tChannelPushDis.setChannelSource(channelSource);
            tChannelPushDis.setChannelPushId(channelPushId);
            tChannelPushDis.setTel(tel);
            // 保存操作信息
            Map<String, String> map = this.disChannelCustomer(tChannelDataConfVo, tChannelPushVo);
            //
            String flag = map.get("flag");
            if (Objects.equals("6", flag)) {
                // 待处理
                tChannelPushDis.setOperateFlag("1");
            } else {
                tChannelPushDis.setOperateFlag("0");
                Map<String, String> mapInfo = new HashMap<>();
                mapInfo.put("operator", tChannelDataConfVo.getChannelName());
                mapInfo.put("operatorUserId", "1");
                mapInfo.put("operatorReason", "正常");
                mapInfo.put("operatorTime", DateUtils.getTime());
                tChannelPushDis.setOperateResult(JsonUtils.toJsonString(mapInfo));
            }
            tChannelPushDis.setDataInfo(JsonUtils.toJsonString(map));
            channelPushDisMapper.insert(tChannelPushDis);
            return map;
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            throw new ServiceException("异常信息：" + e.getMessage());
        }
    }

    @Override
//    @Transactional(propagation = Propagation.NESTED)
//    @Transactional(rollbackFor = Exception.class)
    public Map<String, String> disChannelCustomer(TChannelDataConfVo tChannelDataConfVo,
            TChannelPushVo tChannelPushVo) {
        Map<String, String> map = new HashMap<>();

        String channelName = tChannelDataConfVo.getChannelName();
        Long channelDataId = tChannelDataConfVo.getId();
        // 要分配给谁
        Long disUserId = tChannelDataConfVo.getDisUserId();
        // 拿到要分的人之后 ----- 开始进入分配操作
        String tel = tChannelPushVo.getTel();
        String dataInfo = tChannelPushVo.getDataInfo();

        // 备注信息
        String name = "";
        String remarks = "";
        String ed = "";
        String sex = "";
        // 获取需要的数值  根据不同来源转为不同的对象
        if (Objects.equals(ChannelPushEnum.CRM_CHANNEL.getValue(), tChannelPushVo.getChannelSource())) {
            ChannelRequest channelRequest = JsonUtils.parseObject(dataInfo, ChannelRequest.class);
            if (channelRequest == null) {
                map.put("flag", "1");
                map.put("error_msg", "客户信息获取失败");
                throw new ServiceException("客户信息获取失败");
            }
            name = channelRequest.getCname();
            remarks = channelRequest.getRemarks();
            ed = channelRequest.getEd();
            sex = channelRequest.getSex();
            String time = channelRequest.getSubtime();

            StringBuilder stringBuilder = new StringBuilder();
            if (StringUtils.isNotBlank(remarks)) {
                stringBuilder.append(remarks);
            }
            if (StringUtils.isNotBlank(ed)) {
                stringBuilder.append(" 额度：").append(ed).append(" ");
            }
            if (StringUtils.isNotBlank(time)) {
                stringBuilder.append(" 时间：").append(time).append(" ");
            }
            remarks = stringBuilder.toString();

        } else if (Objects.equals(ChannelPushEnum.CF_CRM_CHANNEL.getValue(), tChannelPushVo.getChannelSource())) {
            CfCrmRequest crmRequest = JsonUtils.parseObject(dataInfo, CfCrmRequest.class);
            if (crmRequest == null) {
                map.put("flag", "1");
                map.put("error_msg", "客户信息获取失败");
                throw new ServiceException("客户信息获取失败");
            }
            name = crmRequest.getName();
            remarks = crmRequest.getRemark();
            ed = crmRequest.getLoanAmount();
            String time = crmRequest.getReceivetime();

            StringBuilder stringBuilder = new StringBuilder();
            if (StringUtils.isNotBlank(remarks)) {
                stringBuilder.append(remarks);
            }
            if (StringUtils.isNotBlank(ed)) {
                stringBuilder.append(" 额度：").append(ed).append(" ");
            }
            if (StringUtils.isNotBlank(time)) {
                stringBuilder.append(" 时间：").append(time).append(" ");
            }
            remarks = stringBuilder.toString();
        } else {
            ChannelCommonRequest channelRequest = JsonUtils.parseObject(dataInfo, ChannelCommonRequest.class);
            if (channelRequest == null) {
                map.put("flag", "1");
                map.put("error_msg", "客户信息获取失败");
                throw new ServiceException("客户信息获取失败");
            }
            name = channelRequest.getCname();
            remarks = channelRequest.getRemarks();
            ed = channelRequest.getEd();
            sex = channelRequest.getSex();
            String time = channelRequest.getSubtime();

            StringBuilder stringBuilder = new StringBuilder();
            if (StringUtils.isNotBlank(remarks)) {
                stringBuilder.append(remarks);
            }
            if (StringUtils.isNotBlank(ed)) {
                stringBuilder.append(" 额度：").append(ed).append(" ");
            }
            if (StringUtils.isNotBlank(time)) {
                stringBuilder.append(" 时间：").append(time).append(" ");
            }
            remarks = stringBuilder.toString();
        }
        // 1、根据手机号判断是否存在总库
        LambdaQueryWrapper<TotalComster> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(TotalComster::getMobile, tel);
        lambdaQueryWrapper.eq(TotalComster::getDelFlag, "0");
        List<TotalComster> totalComsters = totalComsterMapper.selectList(lambdaQueryWrapper);
        // 总库存在 总库id
        Long totalComsterId;
        // 总库不存在、新增到总库
        boolean totalCustomerIsExist = false;
        String totalName = "";
        if (CollectionUtils.isEmpty(totalComsters)) {
            // 新增到总库里面去
            TotalComster totalComster = new TotalComster();
            totalComster.setMobile(tel);
            totalComster.setCustomerFlag("1");
            totalComster.setName(name);
            totalComster.setRemark(remarks);
            totalComster.setImportTime(DateUtils.getTime());
            totalComster.setSex(sex);
            totalComster.setChannelIds(channelDataConfMapper.getChannelIdsByTel(tel));
            totalComster.setLevel("3");
            totalComster.setCustomerStatus(CustomerStatusEnum.XSJ.getCode());
            totalComsterMapper.insert(totalComster);
            totalComsterId = totalComster.getId();
        } else {
            totalComsterId = totalComsters.get(0).getId();
            // 手机号已经存在总库
            totalCustomerIsExist = true;
            totalName = totalComsters.get(0).getName();
        }
        //2、总库存在 ----
        QueryWrapper<Customer> query = Wrappers.query();
        query.eq("total_customer_id", totalComsterId);
        query.eq("deleted", 0);
        CustomerVo customerVo = customerMapper.selectVoOne(query);
        Long customerId;
        // 客户表不存在
        if (customerVo == null) {
            // 保存下推记录
            TCustomerDisRecord disRecord = new TCustomerDisRecord();
            disRecord.setBusType(BusTypeEnum.CHANNEL_PUSH.getCode());
            disRecord.setOperateDisId(-1L);
            disRecord.setOperateDeptId(-1L);
            disRecord.setOperateDisName(channelName);
            // 新增客户
            Customer customer = new Customer();
            customer.setName(name + (StringUtils.isNotBlank(totalName) ? ("-" + totalName) : ""));
            customer.setTel(tel);
            customer.setTotalCustomerId(totalComsterId);
            // 保存备注信息
            if (StringUtils.isNotBlank(remarks)) {
                StringBuilder stringBuilder = new StringBuilder();
                String remarkInfo =
                        remarks + "--" + channelName + "[" + DateUtils.parseDateToStr(
                                DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate()) + "]";
                stringBuilder.append(remarkInfo);
                stringBuilder.append("<br/>");
                customer.setBz(stringBuilder.toString());
            }
            // 客户表id
            Optional.ofNullable(userMapper.selectUserById(disUserId)).ifPresent(it -> {
                customer.setDistributeDeptId(it.getDeptId());
                disRecord.setDisDeptId(it.getDeptId());
                disRecord.setDisName(it.getNickName());
            });
            customer.setCompanyStatus(CompanyStatusEnum.DRL.getCode());
            // 用户ID写入
            customer.setTaskId(disUserId);
            // 更新时间
            customer.setLastRemarkTime(DateUtils.getNowDate());
            customer.setIsPush("0");
            // 分配之前就是新数据
            customer.setIsNew(1);

            // 渠道信息
            customer.setChannelIds(channelDataConfMapper.getChannelIdsByTel(tel));

            // 3星 新数据 -API
            customer.setLevel("3");
            customer.setCustomerStatus(CustomerStatusEnum.XSJ.getCode());

            customerMapper.insert(customer);
            customerId = customer.getId();

            disRecord.setCustomerId(customerId);
            if (StringUtils.isNotBlank(remarks)) {
                // 新增一条备注记录信息
                Remark remark = new Remark();
                remark.setContent(remarks);
                remark.setCustomerId(customerId);
                remark.setCreateBy(channelName);
                remark.setUserId(14L);
                remarkMapper.insert(remark);
            }

            // 更新总库标识----已下发
            TotalComster totalComster = new TotalComster();
            totalComster.setId(totalComsterId);
            totalComster.setCustomerFlag("1");
            totalComster.setChannelIds(channelDataConfMapper.getChannelIdsByTel(tel));
            totalComsterMapper.updateById(totalComster);
            // 发送消息给业务员
            ChannelMsgSent channelMsgSent = new ChannelMsgSent();
            channelMsgSent.setId(disUserId);
            channelMsgSent.setChannelName(channelName);
            channelMsgSent.setTel(tel);
            map.put("sentType", "bus");
            map.put("sentInfo", JsonUtils.toJsonString(channelMsgSent));
            //sentToBusMsg(channelMsgSent);
            System.out.println("发送消息给业务员-----");
            map.put("flag", "0");
            map.put("msg", "分配给业务员成功");
            map.put("history_localhost", (!totalCustomerIsExist ? "新-->总库-->" : "总库-->") + "我的客户");
            map.put("sentMsgType", "busSent");
            map.put("customerId", String.valueOf(customerId));
            map.put("totalCustomerId", String.valueOf(totalComsterId));

            // 分配给哪个部门
            disRecord.setDisUserId(disUserId);
            disRecord.setTaskId(disUserId);
            disRecord.setCustomerName(name);
            disRecord.setOperateDisName(channelName);
            disRecord.setCreateTime(DateUtils.getNowDate());
            disRecordMapper.insert(disRecord);
            return map;
        }
        customerId = customerVo.getId();
        // 判断是否分配到业务员
        Long taskId = customerVo.getTaskId();
        if (taskId != -1) {
            Customer customer = new Customer();
            customer.setId(customerId);
            // 保存备注信息
            if (StringUtils.isNotBlank(remarks)) {
                // 新增一条备注记录信息
                Remark remark = new Remark();
                remark.setContent(remarks);
                remark.setCustomerId(customerId);
                remark.setCreateBy(channelName);
                remark.setUserId(14L);
                remarkMapper.insert(remark);
                StringBuilder stringBuilder = new StringBuilder();
                String remarkInfo =
                        remarks + "--" + channelName + "[" + DateUtils.parseDateToStr(
                                DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate()) + "]";
                stringBuilder.append(remarkInfo);
                stringBuilder.append("<br/>");
                stringBuilder.append(customerVo.getBz());
                customer.setBz(stringBuilder.toString());
            }
            //customer.setName(name + "-" + customerVo.getName());
            customer.setLastRemarkTime(DateUtils.getNowDate());
            customerMapper.updateById(customer);

            // 给管理员发送消息
            System.out.println("推送给管理者进来了-----");
            ChannelMsgSent channelMsgSent = new ChannelMsgSent();
            channelMsgSent.setId(channelDataId);
            channelMsgSent.setChannelName(channelName);
            channelMsgSent.setTel(tel);
//            sentToAdminMsg(channelMsgSent);
            map.put("flag", "6");
            map.put("msg", "推送给管理员");
            map.put("history_localhost", "我的客户");
            map.put("sentType", "admin");
            map.put("sentInfo", JsonUtils.toJsonString(channelMsgSent));
            map.put("customerId", String.valueOf(customerId));
            map.put("totalCustomerId", String.valueOf(totalComsterId));
            return map;
        }

        // 分配给当前人
        Customer customer = new Customer();
        customer.setId(customerId);
        customer.setTaskId(disUserId);
        // 保存下推记录
        TCustomerDisRecord disRecord = new TCustomerDisRecord();
        disRecord.setBusType(BusTypeEnum.CHANNEL_PUSH.getCode());
        disRecord.setCustomerId(customerId);
        disRecord.setOperateDisId(-1L);
        disRecord.setOperateDeptId(-1L);
        disRecord.setOperateDisName(channelName);
        Optional.ofNullable(userMapper.selectUserById(disUserId)).ifPresent(it -> {
            customer.setDistributeDeptId(it.getDeptId());
            disRecord.setDisDeptId(it.getDeptId());
            disRecord.setDisName(it.getNickName());
        });
        // 保存备注信息
        if (StringUtils.isNotBlank(remarks)) {
            // 新增一条备注记录信息
            Remark remark = new Remark();
            remark.setContent(remarks);
            remark.setCustomerId(customerId);
            remark.setCreateBy(channelName);
            remark.setUserId(14L);
            remarkMapper.insert(remark);
            StringBuilder stringBuilder = new StringBuilder();
            String remarkInfo =
                    remarks + "--" + channelName + "[" + DateUtils.parseDateToStr(
                            DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate()) + "]";
            stringBuilder.append(remarkInfo);
            stringBuilder.append("<br/>");
            stringBuilder.append(customerVo.getBz());
            customer.setBz(stringBuilder.toString());
        }
        customer.setName(name + "-" + customerVo.getName());
        customer.setLastRemarkTime(DateUtils.getNowDate());
        // 客户状态为待认领
        customer.setCompanyStatus(CompanyStatusEnum.DRL.getCode());
        // 分配之前就是新数据
        customer.setIsNew(1);
        // 渠道信息
        customer.setChannelIds(channelDataConfMapper.getChannelIdsByTel(tel));
        // 3星 新数据 -API
        customer.setLevel("3");
        customer.setCustomerStatus(CustomerStatusEnum.XSJ.getCode());


        // 记录客户名称变更
        String newOldJson = JsonUtils.toJsonString(customer);
        String oldOldJson = JsonUtils.toJsonString(customerVo);
        CustomerChange newCustomerChange = BeanUtil.toBean(customer, CustomerChange.class);
        CustomerChange oldCustomerChange = BeanUtil.toBean(customerVo, CustomerChange.class);
        Map<String, Object> mapChangeInfo = new HashMap<>();
        mapChangeInfo.put("customerId", customerId);
        mapChangeInfo.put("tel", customerVo.getTel());
        mapChangeInfo.put("createId", 14L);
        mapChangeInfo.put("createBy", channelName);
        mapChangeInfo.put("type", "customerInfoChange");

        customerMapper.updateById(customer);

        // 记录变更记录
        commonService.customerChangeRecord(oldCustomerChange, oldOldJson, newCustomerChange, newOldJson, mapChangeInfo, "1");

        disRecord.setDisUserId(disUserId);
        disRecord.setTaskId(disUserId);
        disRecord.setCustomerName(name);
        disRecord.setOperateDisName(channelName);
        disRecord.setCreateTime(DateUtils.getNowDate());
        disRecordMapper.insert(disRecord);
        // 发送消息给业务员
        ChannelMsgSent channelMsgSent = new ChannelMsgSent();
        channelMsgSent.setId(disUserId);
        channelMsgSent.setChannelName(channelName);
        channelMsgSent.setTel(tel);
        map.put("sentType", "bus");
        map.put("sentInfo", JsonUtils.toJsonString(channelMsgSent));
        //sentToBusMsg(channelMsgSent);
        map.put("flag", "0");
        map.put("msg", "分配给业务员成功");
        map.put("history_localhost", "客户池-->我的客户");
        map.put("customerId", String.valueOf(customerId));
        map.put("totalCustomerId", String.valueOf(totalComsterId));
        return map;
    }

    @Override
//    @Transactional(rollbackFor = Exception.class)
    public void channelDisUserId(Long channelDataId) {
        channelDataConfService.disUserInfoUpdate(channelDataId, "1");
    }



    // 给管理者发送消息 ---- 全发
    @Override
    public void sentToAdminMsg(ChannelMsgSent channelMsgSent) {
        String tel = channelMsgSent.getTel();
        String channelName = channelMsgSent.getChannelName();
        Long channelDataId = channelMsgSent.getId();
        List<TChannelDataStaff> tChannelDataStaffs = channelDataStaffMapper.selectList(
                new LambdaQueryWrapper<TChannelDataStaff>().eq(TChannelDataStaff::getDelFlag, "0")
                        .eq(TChannelDataStaff::getChannelDataId, channelDataId)
                        .eq(TChannelDataStaff::getType, "1")
        );
        if (!CollectionUtils.isEmpty(tChannelDataStaffs)) {
            List<String> collect = tChannelDataStaffs.stream().map(it -> {
                        return String.valueOf(it.getUserId());
                    })
                    .collect(Collectors.toList());
            // 待发送消息
            SentMessage sentMessage = new SentMessage();
            sentMessage.setType(Constants.CHANNEL_PUSH_DIS_ADMIN);
            sentMessage.setOperationName(channelName);
            sentMessage.setUserIds(collect);
            Map<String, String> map = new HashMap<>();
            // 给管理者的消息
            map.put("info", "您有个渠道推送的客户的信息：" + tel + "--信息待处理");
            sentMessage.setContent(JsonUtils.toJsonString(map));
            disCommonService.channelChannelDis(sentMessage);
        }
    }

    // 给分配的业务员发送消息
    @Override
    public void sentToBusMsg(ChannelMsgSent channelMsgSent) {
        String channelName = channelMsgSent.getChannelName();
        Long userId = channelMsgSent.getId();
        System.out.println("业务员ID: " + userId);
        String tel = channelMsgSent.getTel();
        // 待发送消息
        SentMessage sentMessage = new SentMessage();
        sentMessage.setType(Constants.CHANNEL_PUSH_DIS_BUS);
        sentMessage.setOperationName(channelName);
        List<String> userIds = new ArrayList<>();
        userIds.add(String.valueOf(userId));
        sentMessage.setUserIds(userIds);
        Map<String, String> map = new HashMap<>();
        // 给管理者的消息
        map.put("info", "您有个渠道推送的客户的信息：" + tel + "--待查看");
        sentMessage.setContent(JsonUtils.toJsonString(map));
        disCommonService.channelChannelDis(sentMessage);
    }

    @Override
    public void sentToAdminDis(Long userId, String channelName, String msg) {
        // 待发送消息
        SentMessage sentMessage = new SentMessage();
        sentMessage.setType(Constants.CHANNEL_PUSH_DIS_ADMIN);
            sentMessage.setOperationName("系统提醒");
        List<String> userIds = new ArrayList<>();
        userIds.add(String.valueOf(userId));
        sentMessage.setUserIds(userIds);
        Map<String, String> map = new HashMap<>();
        // 给管理者的消息
        map.put("info","您有个渠道消息提醒：" +  channelName + "已无可分配人员");
        sentMessage.setContent(JsonUtils.toJsonString(map));
        disCommonService.channelChannelDis(sentMessage);
    }


}
